<template>
    <div>
        <h1>房号信息更改页面</h1>
        <table class="table">
            <tr>
                <td align="right">房型名称</td>
                <td> <input type="text" v-model="info.name"></td>
            </tr>
               <tr>
                <td align="right">房号</td>
                <td> <input type="text" v-model="info.number"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="更改" @click="add" class="btn btn-primary"></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import {ref,reactive,onMounted} from 'vue'
import { useRoute,useRouter } from 'vue-router';
const router = useRouter();
const route = useRoute();
onMounted(()=>{
    find();
})
const find=()=>{
    axios.get('https://localhost:7267/api/House/GetHouse',{params:{id:route.query.id}}).then(res=>[
    Object.assign(info,res.data)
    ])
}
const info:any =reactive({
    "name":'',
    "number":''
})
const add=()=>{
    axios.put('https://localhost:7267/api/House/HouseUpdate',info).then(res=>{
        if(res.data==-1)
    {
        alert('相同的房号的不能录入多次');
        return;
    }
    if(res.data>0)
    {
        alert('更改成功');
        router.push('/houseshow');
    }
    else
    {
        alert('更改失败');
        return;
    }
    })
}
</script>

<style scoped>

</style>